package es.deusto.ingenieria.aike.formulation;

public class MoveWest extends Operator{
	
	public MoveWest(){
		super("Moving the car WEST");
	}
	
	@Override
	protected State effect(State state) {
		parkingState pState=(parkingState)state.getInformacion();
		parkingState newParking=(parkingState)pState.Clone();
		newParking.moveCar(newParking.getCarPosRow(), newParking.getCarPosCol()-1);
		newParking.setOrientation("WEST");
		return new State(newParking);	
	}

	@Override
	protected boolean isApplicable(State state) {
		parkingState pState=(parkingState)state.getInformacion();
		Cell cell= pState.getCell(pState.getCarPosRow(), pState.getCarPosCol());
		String orientation = pState.getOrientation();
		if (cell.isLeftWall()){
			return false;
		}
		else if (!cell.isCross()&&orientation.equals("WEST")){
			return true;
		}
		else if (cell.isCross()&&(orientation.equals("NORTH")||orientation.equals("SOUTH"))){
			return true;
		}
		else return false;
	}

}
